﻿<html>  
<head>  
<title>发送Json格式数据</title>  
  
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js" ></script>  
<script type="text/javascript" src="js/jquery.json.min.js"></script>  
  
<script type="text/javascript">  
function sendJson() {  
    var requestStr = {  
            reqStr:  'test parameter'  
    };  
    var request = {   
            requestId: 'asdfasdfa',  
            sessionId: 'asdfasdfasdf',  
            userName: 'Jeremy',  
            password:'123',  
            request: requestStr  
    };  
    //调用了jquery.json 库  
    var encoded = $.toJSON( request );  
    var jsonStr = encoded;  
    var actionStr = $("#actionPath").val();  
    $.ajax({  
        url : actionStr,  
        type : 'POST',  
        data : jsonStr,  
        dataType : 'json',  
        contentType : 'application/json',  
        success : function(data, status, xhr) {  
//         Do Anything After get Return data  
//          $.each(data.payload, function(index){  
//              $("#result").append("</br>" + data.payload[index].beanStr);  
//          });  
        },  
        Error : function(xhr, error, exception) {  
            // handle the error.    
            alert(exception.toString());  
        }  
    });  
}  
</script>  
</head>  
<body>  
    <!-- Send JSON -->  
    <B>Action Path:   </B><input id="actionPath"  type="text"  style="width: 300px;"/>  
    <button class="button" id="buttonUpload" style="margin-left:10px;"  
                onclick="return sendJson();">Send</button>  
    <div id="result" >result: </div>  
</body>  
</html>  